home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / OTHER / Printing better / README.TXT < prev    next >
Encoding:
Text File  |  1998-10-24  |  9.6 KB  |  355 lines

  1.  
  2. Printing better.
  3. ----------------
  4.  
  5. This document explains how TeeChart components are
  6. printed, and describes how to improve printing.
  7.  
  8. 1- Introduction
  9. 2- Design issues
  10. 3- How to Print Proportionally?
  11. 4- Other problems
  12. 5- Printing Reference
  13. 6- More information
  14.  
  15.  
  16. 1- Introduction
  17. ----------------
  18.  
  19. The TeeChart library is sending Charts to the printer
  20. using a Windows graphic format known as "metafile".
  21.  
  22. This format has several advantages and disadvantages
  23. over using the bitmap format:
  24.  
  25. - It's much smaller, because graphic information is
  26. stored in vector instructions, instead of pixels.
  27. This results in a faster printing speed in most cases.
  28. Also, the printer doesn't need to have more memory.
  29.  
  30. - Due to be a sequence of instructions instead of 
  31. a fixed array of pixels, a metafile can be resized
  32. ( or "stretched" ) without loosing resolution, and
  33. with greater accuracy.
  34.  
  35. - New printers support metafile format natively, via
  36. software driver or via "gdi hardware".
  37.  
  38. With Windows 32-bit (Windows 95 and Windows NT), an
  39. extended metafile format is implemented. This is known
  40. as "enhanced metafile".
  41. Metafiles have the extension:  "*.wmf" and enhanced
  42. metafiles:  "*.emf".
  43.  
  44.  
  45. 2- Design issues
  46. -----------------
  47.  
  48. The main goal of using metafiles in TeeChart, is to
  49. provide "wysiwyg" (what you see is what you get).
  50. That is, printed charts should look as close as possible
  51. to how they look at screen.
  52.  
  53. To do this, TeeChart creates a metafile of the Chart
  54. image, and then sends this metafile to the printer.
  55.  
  56. At this point, the Windows GDI module and the 
  57. Windows Printer driver will take care of "painting" the
  58. Chart image on paper.
  59.  
  60. This involves "stretching" or "resizing" the metafile,
  61. from screen coordinates to printer logical pixels.
  62.  
  63. Example: 
  64. A Chart on screen is at rectangle: 
  65.  Left  : 100
  66.  Top   : 100
  67.  Right : 300
  68.  Bottom: 400
  69.  
  70. And it gets printed at this paper rectangle:
  71.  Left  : 400 
  72.  Top   : 1000
  73.  Right : 1200
  74.  Bottom: 1500
  75.  
  76. In this example, the Chart should be rescaled both
  77. in width and height:
  78.  
  79. screen Width = 300 - 100 = 200
  80. paper Width = 1200 - 400 = 800
  81. relation screen / paper = 800 / 200 = 4  <---
  82.  
  83. screen Height = 400 - 100 = 300
  84. paper Height = 1500 - 1000 = 500
  85. relation screen / paper = 500 / 300 = 1.666...  <---
  86.  
  87.  
  88. The problem is the relation between the horizontal
  89. and vertical increments is not the same:
  90.  
  91.  4 <> 1.666... 
  92.  
  93. This means the Chart will be expanded more in the
  94. horizontal dimension than in the vertical dimension.
  95.  
  96. In this case, Windows increases font sizes and pen
  97. widths using the new dimensions.
  98.  
  99. Note: Windows 16-bit ( 3.1, 3.11 ) do not resize
  100. fonts as it does Windows 32-bit (95 and NT).
  101. Text can overlap other Chart sections and look bad
  102. positioned.
  103. To fix this, see below "How to print proportionally?"
  104.  
  105. Windows 32-bit does a better job using the enhanced
  106. metafile format, so text dimensions are calculated
  107. precisely.
  108.  
  109.  
  110. 3- How to Print Proportionally?
  111. -----------------------------
  112.  
  113. By default, the TChart components are printed
  114. using margins that make the paper resulting chart
  115. with the same proportions between width and height
  116. than the screen chart.
  117. This is controlled with the Chart1.PrintProportional
  118. property.
  119. The Print Preview dialog has a check-box to set
  120. PrintProportional to True or False.
  121.  
  122. Some printers can show problems when printing
  123. Charts *without* using proportional printer margins.
  124. Specially in Windows 16-bit with Delphi 1.0
  125. So, the PrintProportional property is recommended to
  126. be True (the default).
  127.  
  128. One approach that allows you full control is to
  129. create a metafile image ( TMetafile ) and then Draw the
  130. Chart into it, and then send the image to the printer.
  131. There is an example included.
  132. This is the most low level printing operation you can do.
  133.  
  134. Another approach is to do the opposite. 
  135. To resize the Chart onscreen to match the desired proportion of 
  136. the printed paper chart:
  137.  
  138.   Chart1.Height:=Round(1.0*Printer.PageHeight*Chart1.Width/Printer.PageWidth);
  139.   Chart1.Print;
  140.  
  141.  
  142. 4- Other problems
  143. =====================
  144.  
  145. Increasing resolution:
  146. ----------------------
  147.  
  148. The metafile format is not aware of the "resolution"
  149. concept. 
  150. This is means resolution information is not stored inside
  151. the metafile image.
  152.  
  153. You can modify the Chart "resolution" *before* printing,
  154. by setting this property:
  155.  
  156. Chart1.PrintResolution := -100 ;
  157.  
  158. Negative values (like -100 above), represent the porcentual
  159. increment in resolution.
  160. Zero means "wysiwyg".
  161.  
  162. More resolution is obtained by making all Chart fonts
  163. smaller and thinner lines.
  164. The metafile size is bigger when using more resolution.
  165.  
  166. Increasing resolution can improve inaccuracy in buggy
  167. printer drivers calculations.
  168.  
  169.  
  170. Printing non-solid lines:
  171. -------------------------
  172.  
  173. In some printer / windows combinations, non-solid pen lines
  174. such as "dot" or "dash" will be printed as solid.
  175. This happens specially in some HP Laserjet printers.
  176.  
  177. It seems the only workaround is to set the Chart Pen Width
  178. properties to Zero:
  179.  
  180. Chart1.LeftAxis.Grid.Width := 0;
  181.  
  182. Increasing resolution ( see above ) can make the printer
  183. to show non-solid lines.
  184.  
  185. Colors:
  186. ---------
  187.  
  188. Many printers accept only a subset of the available Colors.
  189. This means setting a Chart color to a non-supported 
  190. palette color may result in that color not being used by
  191. the printer, thus not drawing anything.
  192.  
  193. In this situations, try with "well known" solid colors like
  194. "clRed, clBlue, clYellow, clGreen".
  195.  
  196. Some printers include a "Color Mapping" configuration dialog.
  197. (At Printer Properties dialog).
  198.  
  199.  
  200. Printing directly:
  201. ------------------
  202.  
  203. Drawing a Chart directly onto a Printer GDI Handle or Canvas
  204. is also possible.
  205. The following code does it:
  206.  
  207.  Uses Printers;
  208.  With Printer do
  209.  begin 
  210.    BeginDoc;
  211.    try
  212.      Chart1.Draw( Canvas, Rect( 0,0,PageWidth,PageHeight ) );
  213.    finally
  214.      EndDoc;
  215.    end;
  216.  end; 
  217.  
  218. You will see several problems printing directly:
  219.  
  220. -- The Chart background is gray color ( instead of white ).
  221. -- Font sizes are extremely small.
  222. -- There are many axis grid lines.
  223. -- Lines are very thin.
  224.  
  225. One way to solve the above problems is using the metafile
  226. printing mode, described in this document.
  227.  
  228. Another way (much more complicated) is to change all Font
  229. sizes and pen Width properties.
  230.  
  231.  
  232. Printer driver settings:
  233. ------------------------
  234.  
  235. Try to use always the latest "good" printer driver version.
  236. Try changing the Windows Printer driver resolution settings,
  237. and the spooler method (in Windows NT) to both "EMF" and
  238. "RAW" modes.
  239.  
  240. "EMF" means all output is sent to the printer in metafile format.
  241.  
  242.  
  243.  
  244. 5- Printing Reference
  245. ========================
  246.  
  247. See the help file for extended information and examples
  248. on the following properties and methods.
  249.  
  250. The BASIC.PAS and UPRINT.PAS units in TeeDemo project
  251. contain code showing custom printing.
  252.  
  253. The attached project shows Printing Margin adjustments 
  254. to avoid text overlaping in Delphi 1.0 on 16-bit Windows 
  255. systems.
  256.  
  257. Printing Properties:
  258. ---------------------
  259.  
  260. Properties involved in Chart printing are:
  261.  
  262. Chart1.PrintMargins   
  263.   The percentual space at the four sides of the paper page.
  264.  
  265. Chart1.PrintResolution   
  266.   The relation between screen dimensions and paper dimensions.
  267.  
  268. Chart1.PrintProportional
  269.   True to set the paper margins to match screen proportions.
  270.  
  271. Printing methods:
  272. -----------------
  273.  
  274. The TeeChart control has several methods designed for
  275. printing:
  276.  
  277. Methods that print *and* eject the printed page:
  278. =================================================
  279.  
  280. These are the default and more used TeeChart printing 
  281. methods.
  282.  
  283. Chart1.Print           
  284.   Uses default paper orientation and margins.
  285.  
  286. Chart1.PrintPortrait   
  287.   Sets paper in Portrait and uses default margins.
  288.  
  289. Chart1.PrintLandscape  
  290.   Sets paper in Landscape and uses default margins.
  291.  
  292. Chart1.PrintRect       
  293.   Uses default paper orientation and the Rect parameter to 
  294.   position the Chart on the page.  
  295.  
  296.  
  297. Methods that do not eject the printed page:
  298. ============================================
  299.  
  300. These methods allow printing more than one chart in the same
  301. paper page, or print other things and Chart components on the
  302. same page.
  303.  
  304. With these methods you need to call Printer.BeginDoc and EndDoc
  305. yourself. See Delphi TPrinter documentation and the UPRINT.PAS
  306. and BASIC.PAS units in TeeChart TEEDEMO project.
  307.  
  308. Chart1.PrintPartial    
  309.    Draws a Chart to the Printer Canvas at the passed rectangle.
  310.  
  311. Chart1.PrintPartialCanvas   
  312.    Draws a Chart to the passed Canvas at the passed rectangle.
  313.  
  314.  
  315. Related methods and properties:
  316. ===============================
  317.  
  318. Not directly involved with printing, but useful for
  319. advanced printing:
  320.  
  321. Chart1.Draw
  322.    Draws a Chart to the passed Canvas, in screen "mode".
  323.    "Screen mode" means with gray background and without 
  324.    using the metafile format.
  325.    This method draws directly to the Canvas.
  326.  
  327. Chart1.TeeCreateMetafile
  328.    Function that returns a metafile image of the Chart,
  329.    with the passed Rect coordinates.
  330.  
  331. Chart1.Metafiling
  332.    Boolean property indicating the Chart is now drawing
  333.    onto a metafile image.
  334.  
  335. Chart1.Printing
  336.    Boolean property indicating the Chart is now drawing
  337.    onto a Printer Canvas.
  338.  
  339.  
  340. 6- More information:
  341. ====================
  342.  
  343. Information about printing and metafiles can be found
  344. at Microsoft Windows 32-bit SDK help file, located at:
  345.  
  346. "..\Delphi 3(4)\(Borland Shared\Microsoft Help)Help\Win32.hlp"
  347.  
  348. Use the "Help Contents" (not the index) and scroll-down
  349. up to the Metafiles chapter.
  350.  
  351. See also the Delphi's TMetafile and TMetafileCanvas objects
  352. at Delphi's help file and GRAPHICS.PAS unit.
  353.  
  354. -------------------------------------------------------
  355.